package cn.service.impl;

import cn.mapper.HealthVaccineMapper;
import cn.pojo.HealthVaccine;
import cn.service.HealthVaccineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HealthVaccineServiceImpl implements HealthVaccineService {
    @Autowired
    private HealthVaccineMapper vaccineMapper;


    @Override
    public Map<String, Object> selectVaccine(HealthVaccine vaccine) {
        Map<String, Object> res = new HashMap<>();
        List<HealthVaccine> healthVaccines = null;
        try {
            healthVaccines = vaccineMapper.selectVaccine(vaccine);
            res.put("msg", healthVaccines);
        } catch (Exception e) {
            e.printStackTrace();
            res.put("msg", false);
        }

        return res;
    }

    @Override
    public Map<String, Object> updateVaccine(HealthVaccine vaccine) {
        Map<String, Object> res = new HashMap<>();

        boolean ok = false;
        try {
            ok = vaccineMapper.updateVaccine(vaccine) == 1;
        } catch (Exception e) {
            ok = false;
            e.printStackTrace();
        }
        res.put("msg", ok);
        return res;
    }

    @Override
    public Map<String, Object> saveVaccine(HealthVaccine vaccine) {
        Map<String, Object> res = new HashMap<>();

        boolean ok = false;
        try {
            ok = vaccineMapper.saveVaccine(vaccine) == 1;
        } catch (Exception e) {
            ok = false;
            e.printStackTrace();
        }
        res.put("msg", ok);
        return res;
    }
}
